<?php defined('SYSPATH') or die();?>
<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <title>线路订单管理-思途CMS{$coreVersion}</title>
    {template 'stourtravel/public/public_js'}
    {php echo Common::getCss('style.css,base.css,base_new.css'); }
    {php echo Common::getScript("jquery.buttonbox.js,choose.js"); }
</head>
<body style="overflow:hidden">

<table class="content-tab">
    <tr>
        <td width="119px" class="content-lt-td" valign="top">
            {template 'stourtravel/public/leftnav'}
            <!--右侧内容区-->
        </td>
        <td valign="top" class="content-rt-td" style="overflow:hidden">
            <div class="cfg-header-bar">
                {template 'stourtravel/public/member_top'}
            </div>
            <div class="cfg-header-bar" style="background: white;">
                <div class="fl select-box w100 mt-3 ml-10">
                    <select name="typeid" data-fieldname="typeid" onchange="togStatusChange(this)" class="select">
                        <option value="0">产品类型</option>
                        {loop $all_modle $key $v}
                        <option value="{$v['id']}">{$v['modulename']}</option>
                        {/loop}
                    </select>
                </div>
                <div class="fl select-box w100 mt-3 ml-10">
                    <select name="status" data-fieldname="status" onchange="togStatusChange(this)" class="select">
                        <option value="">订单状态</option>
                        {loop $order_status $key $v}
                        <option value="{$key}">{$v}</option>
                        {/loop}
                    </select>
                </div>

                <div class="cfg-header-order-info">
                    <span class="item">订单总数：<span id="total_num" class="c-orange"></span></span>
                    <span class="item">已支付：<span id="pay_num" class="c-orange"></span></span>
                    <span class="item">未支付：<span id="unpay_num" class="c-orange"></span></span>
                    <span class="item">订单总金额：<span id="total_price" class="c-orange"></span></span>
                    <span class="item">已支付金额：<span id="pay_price" class="c-orange"></span></span>
                    <span class="item">未支付金额：<span id="unpay_price" class="c-orange"></span></span>
                </div>

                <a href="javascript:;" class="fr btn btn-primary radius mt-6 mr-10" onclick="window.location.reload()">刷新</a>
            </div>
            <div id="product_grid_panel" class="content-nrt" >

            </div>
        </td>
    </tr>
</table>
<input type="hidden" name="mid" value="{$mid}" >
<script>
    $(function () {

        var mid = $("input[name='mid']").val();

        $.getJSON(SITEURL+'member/ajax_sell_info/mid/'+mid,function(data){
            $("#total_num").html(data.total_num);
            $("#pay_num").html(data.pay_num);
            $("#unpay_num").html(data.unpay_num);
            $("#total_price").html(data.total_price);
            $("#pay_price").html(data.pay_price);
            $("#unpay_price").html(data.unpay_price);
        });


    });
    window.display_mode = 1;	//默认显示模式
    window.product_kindid = 0;  //默认目的地ID


    window.statusmenu={json_encode($statusnames)};
    window.paysources={json_encode($paysources)};


    Ext.onReady(
        function () {
            Ext.tip.QuickTipManager.init();
            //var editico = "{php echo Common::getIco('edit');}";
            var delico = "{php echo Common::getIco('del');}";
            var editico = "{php echo Common::getIco('order');}";
            var unviewico="{php echo Common::getIco('order_unview');}";

            $("#searchkey").focusEffect();
            //产品store
            window.product_store = Ext.create('Ext.data.Store', {
                fields: [
                    'id',
                    'typeid',
                    'ordersn',
                    'productname',
                    'addtime',
                    'usedate',
                    'dingnum',
                    'price',
                    'totalprice',
                    'childprice',
                    'childnum',
                    'linkman',
                    'linktel',
                    'status',
                    'viewstatus',
                    'paysource',
                    'dingjin',
                    'paytype',
                    'statusname',
                    'online_refund_status',
                    'source',
                    'pay_way',
                    'suppliername',
                    'modulename',
                    'pinyin'
                ],

                proxy: {
                    type: 'ajax',
                    api: {
                        read: SITEURL+"member/order_list/mid/{$mid}/act/read/",  //读取数据的URL
                        update: SITEURL+"member/order_list/mid/{$mid}/act/save/",
                        destroy: SITEURL+"member/order_list/mid/{$mid}/act/delete/"
                    },
                    reader: {
                        type: 'json',   //获取数据的格式
                        root: 'list',
                        totalProperty: 'total'
                    }
                },
                remoteSort: true,
                pageSize: 15,
                autoLoad: true,
                listeners: {
                    load: function (store, records, successful, eOpts) {
                        if(!successful){
                            ST.Util.showMsg("{__('norightmsg')}",5,1000);
                        }
                        var pageHtml=ST.Util.page(store.pageSize,store.currentPage,store.getTotalCount(),10);
                        $("#line_page").html(pageHtml);
                        window.product_grid.doLayout();
                        $(".pageContainer .pagePart a").click(function () {
                            var page = $(this).attr('page');
                            product_store.loadPage(page);
                        });
                    }
                }

            });

            //产品列表
            window.product_grid = Ext.create('Ext.grid.Panel', {
                store: product_store,
                renderTo: 'product_grid_panel',
                border: 0,
                width: "100%",
                bodyBorder: 0,
                bodyStyle: 'border-width:0px',
                scroll:'vertical', //只要垂直滚动条
                bbar: Ext.create('Ext.toolbar.Toolbar', {
                    store: product_store,  //这个和grid用的store一样
                    displayInfo: true,
                    emptyMsg: "",
                    items: [
                        {
                            xtype:'panel',
                            id:'listPagePanel',
                            html:'<div id="line_page"></div>'
                        },
                        {
                            xtype: 'combo',
                            fieldLabel: '每页显示数量',
                            width: 170,
                            labelAlign: 'right',
                            forceSelection: true,
                            value: 15,
                            store: {fields: ['num'], data: [
                                {num: 15},
                                {num: 30},
                                {num: 50}
                            ]},
                            displayField: 'num',
                            valueField: 'num',
                            listeners: {
                                select: changeNum
                            }
                        }

                    ],

                    listeners: {
                        single: true,
                        render: function (bar) {
                            bar.insert(0, Ext.create('Ext.toolbar.Fill'));
                        }
                    }
                }),
                columns: [
                    {
                        text: '订单号',
                        width: '10%',
                        dataIndex: 'ordersn',
                        align: 'center',
                        border: 0,
                        sortable: false,
                        menuDisabled:true,
                        renderer: function (value, metadata, record) {
                            return value;
                        }

                    },

                    {
                        text: '产品类型',
                        width: '10%',
//                        xtype:'templatecolumn',
                        tdCls: 'product-ch',
                        align: 'center',
                        dataIndex: 'modulename',
                        menuDisabled:true,
                        border: 0,
                        renderer: function (value, metadata, record) {
                            return  value;
                        }

                    },
                    {
                        text: '产品名称',
                        width: '30%',
                        dataIndex: 'productname',
                        align: 'left',
                        border: 0,
                        sortable: false,
                        menuDisabled:true,
                        renderer: function (value, metadata, record) {
                            var producturl=record.get('producturl');
                            return "<a href='"+producturl+"' target='_blank'>"+value+"</a>";
                        }

                    },
                    {
                        text: '订单状态',
                        width: '5%',
                        dataIndex: 'status',
                        align: 'center',
                        border: 0,
                        cls:'sort-col',
                        sortable: true,
                        menuDisabled:true,
                        renderer: function (value, metadata, record) {
                            var status_name=record.get('statusname');
                            var status=record.get('status');
                            var online_refund_status=record.get('online_refund_status');
                            if(status==6&&online_refund_status==2)
                            {
                                status_name += '<i style="color: red">(退款失败)</i>';
                            }
                            return status_name;
                        }

                    },
                    {
                        text: '预订时间',
                        width: '10%',
                        dataIndex: 'addtime',
                        align: 'center',
                        border: 0,
                        cls:'sort-col',
                        sortable: true,
                        menuDisabled:true,
                        renderer: function (value, metadata, record) {
                            return value;
                        }
                    },
                    {
                        text: '消费日期',
                        width: '10%',
                        dataIndex: 'usedate',
                        align: 'center',
                        border: 0,
                        cls:'sort-col',
                        sortable: true,
                        menuDisabled:true,
                        renderer: function (value, metadata, record) {
                            return value;
                        }
                    },
                    {
                        text: '预订数量',
                        width: '5%',
                        dataIndex: 'dingnum',
                        align: 'center',
                        border: 0,
                        cls:'sort-col',
                        sortable: true,
                        menuDisabled:true,
                        renderer: function (value, metadata, record) {
                            return value;

                        }

                    },
                    {
                        text: '订单金额',
                        width: '10%',
                        dataIndex: 'totalprice',
                        align: 'center',
                        border: 0,
                        sortable: false,
                        menuDisabled:true,
                        renderer: function (value, metadata, record) {
                            var dingjin=record.get('dingjin');
                            var paytype=record.get('paytype');
                            var prefix=dingjin>0&&paytype==2?'定金 ':'';
                            var str='';
                            if(value>0){
                                str+=prefix+value;
                            }
                            if(record.get('paysource')){
                                str+='<br>' +record.get('paysource');
                            }
                            return str;
                        }
                    },
                    {
                        text: '管理',
                        width: '10%',
                        align: 'center',
                        border: 0,
                        sortable: false,
                        menuDisabled:true,
                        cls: 'mod-1',
                        renderer: function (value, metadata, record) {
                            var id = record.get('id');
                            var typeid = record.get('typeid');
                            var pinyin = record.get('pinyin');
                            var viewstatus=record.get('viewstatus');
                            var ico=viewstatus==1?editico:unviewico;
                            var html = "<a href='javascript:void(0);' onclick=\"view(" + id + ","+typeid+",'"+pinyin+"')\">详情</a>";
                            return html;
                        }
                    }
                ],
                listeners: {
                    boxready: function () {
                        var height = Ext.dom.Element.getViewportHeight();
                        this.maxHeight = height-76 ;
                        this.doLayout();
                    },
                    afterlayout: function (grid) {

                    }
                },
                plugins: [
                    Ext.create('Ext.grid.plugin.CellEditing', {
                        clicksToEdit: 2,
                        listeners: {
                            edit: function (editor, e) {
                                var id = e.record.get('mid');
                                //  var view_el=window.product_grid.getView().getEl();
                                //  view_el.scrollBy(0,this.scroll_top,false);
                                updateField(0, id, e.field, e.value, 0);
                                return false;

                            }

                        }
                    })
                ],
                viewConfig: {
                    enableTextSelection:true
                }
            });
        });

    //实现动态窗口大小
    Ext.EventManager.onWindowResize(function () {
        var height = Ext.dom.Element.getViewportHeight();
        var data_height = window.product_grid.getView().getEl().down('.x-grid-table').getHeight();
        if (data_height > height - 76)
            window.product_grid.height = (height - 76);
        else
            delete window.product_grid.height;
        window.product_grid.doLayout();

    });


    function selecteViewed(ids){
        Ext.Ajax.request({
            url   :  SITEURL+"order/viewed",
            method  :  "POST",
            datatype  :  "JSON",
            params:{ids:ids.join(',')},
            success  :  function(response, opts)
            {
                if(response.responseText=='ok')
                {
                    var record;
                    $.each(ids,function(index,value){
                        record=window.product_store.getById(value.toString());
                        record.set('viewstatus',1);
                        record.commit();
                    });
                }
                else
                {
                    ST.Util.showMsg("{__('norightmsg')}",5,1000);
                }
            }
        });
    }

    /**
     * 状态改变
     * @param ele
     */
    function togStatusChange(ele){
        var v=$(ele).val();
        var fieldname = $(ele).data('fieldname');

        window.product_store.getProxy().setExtraParam(fieldname,v);
        window.product_store.loadPage(1);

    }


    $(function(){

    });

    //切换每页显示数量
    function changeNum(combo, records) {
        var pagesize=records[0].get('num');
        window.product_store.pageSize=pagesize;
        window.product_store.loadPage(1);
    }
    //更新某个字段
    function updateField(ele, id, field, value, type) {
        var record = window.product_store.getById(id.toString());
        if (type == 'select') {
            value = Ext.get(ele).getValue();
        }
        var view_el = window.product_grid.getView().getEl();

        Ext.Ajax.request({
            url: SITEURL+"line/admin/order/index/action/update/",
            method: "POST",
            datatype: "JSON",
            params: {id: id, field: field, val: value, kindid: 0},
            success: function (response, opts) {
                if (response.responseText == 'ok') {
                    record.set(field, value);
                    record.commit();
                }
            }});

    }

    //刷新保存后的结果
    function refreshField(id, arr) {
        id = id.toString();
        var id_arr = id.split('_');
        Ext.Array.each(id_arr, function (num, index) {
            if (num) {
                var record = window.product_store.getById(num.toString());

                for (var key in arr) {
                    record.set(key, arr[key]);
                    record.commit();
                }
            }
        })
    }


    //查看订单
    function view(id,typeid,pinyin)
    {
        var record = window.product_store.getById(id.toString());
        var url=SITEURL+pinyin+"/admin/order/view/{if isset($_GET['menuid'])}menuid/{$_GET['menuid']}/{/if}id/"+id+"/typeid/"+typeid;
        ST.Util.addTab('订单详细：'+record.get('ordersn'),url,1);

    }

</script>

</body>
</html>